﻿using System;
using System.Data;
using System.Data.Common;
using System.IO;
using KZ.Express.H.ENT;
using KZ.Utilities;
using System.Data.SqlClient;
using System.Configuration;


namespace KZ.Express.H.DAL
{
    public class LogDAL : BaseDAL
    {
        #region Get log methods

        public static DataTable GetDataTable(DateTime from, DateTime to, string func, string orderBy, string orderDirection)
        {
            try
            {
                //DbCommand dbCommand = AccessDataHelper._Database.GetStoredProcCommand("procLogGetList");

                //AccessDataHelper._Database.AddInParameter(dbCommand, "@LanguageID", DbType.Int32, Utility.LanguageID);
                //AccessDataHelper._Database.AddInParameter(dbCommand, "@From", DbType.DateTime, from);
                //AccessDataHelper._Database.AddInParameter(dbCommand, "@To", DbType.DateTime, to);
                //AccessDataHelper._Database.AddInParameter(dbCommand, "@Function", DbType.String, func);
                //AccessDataHelper._Database.AddInParameter(dbCommand, "@OrderBy", DbType.String, orderBy);
                //AccessDataHelper._Database.AddInParameter(dbCommand, "@OrderDirection", DbType.String, orderDirection);

                //DataSet ds = AccessDataHelper._Database.ExecuteDataSet(dbCommand);
                //return ds.Tables[0];
                return null;
            }
            catch (ConfigurationException ex)
            {
                LogDAL.LogEx("BLM.ERR.Configuration", ex);
                throw new DataAccessException("BLM.ERR.Configuration");
            }
            catch (SqlException ex)
            {
                LogDAL.LogEx("BLM.ERR.Log.GetList", ex);
                throw new DataAccessException("BLM.ERR.Log.Get");
            }
            catch (Exception ex)
            {
                LogDAL.LogEx("BLM.ERR.Log.GetList", ex);
                throw new DataAccessException("BLM.ERR.Log.Get");
            }
        }

        #endregion Get log methods

        public static void LogEx(string ExCode, Exception ex)
        {
            //if (String.IsNullOrWhiteSpace(Utility.LogPath))
            //    Utility.LogPath = Utility.AppPath + @"\log.txt";

            //FileStream fs;
            //if (!File.Exists(Utility.LogPath))
            //    fs = File.Open(Utility.LogPath, FileMode.OpenOrCreate);
            //else
            //    fs = File.Open(Utility.LogPath, FileMode.Append);

            //using (StreamWriter sw = new StreamWriter(fs))
            //{
            //    string Str = "----------------header------------------------\r\n";
            //    Str = Str + "Timestamp: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
            //    Str = Str + "\r\nExceptionCode: " + ExCode;
            //    Str = Str + "\r\nMessage: " + ex.Message;
            //    Str = Str + "\r\nStackTrace:\r\n" + ex.StackTrace;
            //    Str = Str + "\r\nSource: " + ex.Source;
            //    Str = Str + "\r\n\r\n";
            //    sw.Write(Str);
            //    sw.Close();
            //}
            //fs.Close();
        }
    }
}
